package logic

import (
	"context"
	"pro-train-hub/trainrpc/trainrpc"

	"pro-train-hub/api/internal/svc"
	"pro-train-hub/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLessonLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddLessonLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLessonLogic {
	return &AddLessonLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddLessonLogic) AddLesson(req *types.AddLessonRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	data, err := l.svcCtx.TrainRpc.AddLessons(l.ctx, &trainrpc.AddLessonsRequest{
		Info:    req.Info,
		Area:    req.Area,
		Picture: req.Picture,
		UserId:  req.UserId,
		Title:   req.Title,
		Price:   req.Price,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "课程添加成功",
		Code:    200,
		Data:    data,
	}, nil
}
